<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test2</title>
    <link rel="icon" th:href="@{/favicon.png}" type="image/png"/>
    <script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<!--游戏开始相关API测试测试-->
<div id="app">
    <button @click="startGame">开始</button>
    <button @click="getAllCost">获取全部模块升级消费</button>
    <button @click="stageUp">状态升级</button>
    <button @click="turn">回合结算</button>
</div>
<script type="module">
    const { createApp } = Vue

    createApp({
        data() {
            return {
                username: 'Wooming',
                password: 'MyServer123456'
            }
        },
        created(){
            axios.post('../../api/public/login',{
                username: this.username,
                password: this.password
            }).then((response) => {
                console.log(response.data.code)
                // 存储于 localStorage
                localStorage.setItem('jwt', response.data.data)
            })
        },
        methods: {
            startGame() {
                axios.get('../../api/game/start', {
                    headers: {
                        'Content-Type': 'application/json',
                        'Authorization': 'Bearer ' + localStorage.getItem('jwt')
                    }
                }).then((r) => {
                    console.log(r.data)
                })
            },
            getAllCost() {
                axios.get('../../api/game/cost', {
                    headers: {
                        'Content-Type': 'application/json',
                        'Authorization': 'Bearer ' + localStorage.getItem('jwt')
                    }
                }).then((r) => {
                    console.log(r.data)
                })
            },
            stageUp() {
                axios.post('../../api/game/stageUp',{},{
                    headers: {
                        'Content-Type': 'application/json',
                        'Authorization': 'Bearer ' + localStorage.getItem('jwt')
                    }
                }).then((r) => {
                    console.log(r.data)
                    if (r.data.code === 200) {
                        alert('升级成功')
                        localStorage.setItem('jwt', r.data.data)
                    }
                })
            },
            turn() {
                axios.post('../../api/game/turn',{
                    publicityCost: 0
                },{
                    headers: {
                        'Content-Type': 'application/json',
                        'Authorization': 'Bearer ' + localStorage.getItem('jwt')
                    }
                }).then((r) => {
                    console.log(r.data)
                })
            }
        }
    }).mount('#app')
</script>
</body>
</html>